package com.vast.ui.component.commands;

import java.io.DataOutputStream;

import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.widgets.Display;

import com.vast.ui.component.models.Led;
import com.vast.ui.component.models.LedPanel;

public class LedUpdate implements Command {
	protected int no;
	protected int value;
	protected Display display;
	protected LedPanel ledPanel;
	protected TableViewer viewer;
	
	public LedUpdate( Display display, LedPanel ledPanel, TableViewer viewer, int no, int value) {
		this.no       = no;
		this.value    = value;
		this.ledPanel = ledPanel;
		this.viewer   = viewer;
	}
	
	@Override
	public void execute() {
		// TODO Auto-generated method stub
		Led led = new Led(no, value);

		if( no <= ledPanel.getList().size()) {
			ledPanel.changeTarget(no, led);
			display.asyncExec(new Runnable() {
				public void run() {
					viewer.setInput(ledPanel);
				}
			});
		}
	}

}
